#include "widget.h"
#include "ui_widget.h"
#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QDateTime timeOld = ui->dateTimeEdit->dateTime();
    QDateTime timeNew = ui->dateTimeEdit_2->dateTime();

    // 计算日期差值
    int dayOld = timeOld.daysTo(timeNew); // 有一定问题, 无脑进一天
    qDebug() << dayOld;

    int seconds = timeOld.secsTo(timeNew);
    int hours = (seconds / 3600) % 24;
    int day = (seconds / 3600) / 24;
    qDebug() << "相差 " << day << " 天" << "零 " << hours << " 小时";
}
